<template>
  <div class="list-container" :style="{ height: `${listHeight}px` }">
    <div class="content" v-if="allObjects.length > 0">
      <div
        v-for="(item, index) in allObjects"
        :key="index"
        :class="['allObjects-item', item.isSelected ? 'selected' : '']"
        :style="{
          width: `${listHeight - 20}px`,
          height: `${listHeight - 20}px`,
        }"
        @click="handleChoseitem(index)"
      >
        <div class="text-title">
          <lampCom
            :text="item.text"
            :containerWidth="listHeight - 40"
            :speed="30"
          />
        </div>
        <i class="el-icon-close" @click.stop="deleteObject(index)" />
        <dynamicForm
          v-show="false"
          ref="dynamicForm"
          :allObjectsid="item.allObjectsid"
          :type="item.type"
          :configFormOld="item.configFormOld ? item.configFormOld : {}"
          @giveFormtoParent="giveFormtoParent"
        />
      </div>
    </div>
    <div v-else class="no-data">
      <span>点位列表区域</span>
    </div>
  </div>
</template>

<script>
import lampCom from "@/components/Lamp/index2.vue";
import dynamicForm from "@/components/Dynamicform";
export default {
  name: "list",
  components: {
    dynamicForm,
    lampCom,
  },
  props: {
    allObjects: {
      type: Array,
      default: () => [],
    },
    listHeight: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {};
  },
  mounted() {},
  methods: {
    giveFormtoParent(formvalue) {
      this.allObjects.forEach((item) => {
        if (item.allObjectsid === formvalue.allObjectsid) {
          item.configForm = formvalue;
        }
      });
    },
    deleteObject(index) {
      this.$emit("deleteObject", index);
    },
    handleChoseitem(index) {
      console.log(index);
      this.$emit("handleChoseitem", index);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/index.scss";
.list-container {
  width: 100%;
  box-sizing: border-box;
  border: 2px solid rgb(235, 238, 245);
  box-shadow: rgba(0, 0, 0, 0.1) 0px 2px 12px 0px;
  padding: 10px;
  .content {
    width: auto;
    height: auto;
    display: flex;
    justify-content: flex-start;
    white-space: nowrap;
    overflow-x: auto;
    @include scrollBar2;
    .allObjects-item {
      box-sizing: border-box;
      border-radius: 10px;
      border: 2px solid rgb(235, 238, 245);
      box-shadow: rgba(0, 0, 0, 0.1) 0px 2px 12px 0px;
      padding: 10px;
      margin-right: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
      cursor: pointer;
      .text-title {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .el-icon-close {
        position: absolute;
        top: 5px;
        right: 5px;
        cursor: pointer;
        color: #ff4d4f;
        font-size: 18px;
        font-weight: bold;
      }
    }
    .selected {
      border: 2px solid red;
    }
  }
  .no-data {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    span {
      font-size: 18px;
      font-weight: bold;
      color: $themeColor;
    }
  }
}
</style>
